#include "stdio.h"
void shan(char b[], int flag) {
	int i = 0;
	int k;
	while (b[i] != '\0') {
		++i;
	}
	for (k = flag;k < i;k++) {
		b[k] = b[k + 1];
	}
	b[i] = '\0';
}
void tian(char b[], int j, char ch) {
	int i = 0;
	int k;
	while (b[i] != '\0') {
		++i;
	}
	for (k = i - 1;k >= j;k--) {
		b[k + 1] = b[k];
	}
	b[j] = ch;
	b[i + 1] = '\0';
}
void print(char b[]) {
	int i = 0;
	int k;
	while (b[i] != '\0') {
		++i;
	}
	for (k = 0;k < i;k++) {
		printf("%c", b[k]);
	}
}
int main() {
	char str[1000] = { 0 };
	char ch;
	int N, k, i, j;
	int n;
	int flag = 0;
	gets(str);
	scanf("%d  %c\n", &N, &ch);
	for (n = N;n > 0;n--) {
		scanf("%d%d", &i, &j);
		for (k = i - 1;k < j;k++) {
			if (str[k] == ch) {
				flag = k;
				break;
			}
		}
		if (flag != 0) {
			shan(str, flag);
		}
		else {
			tian(str, j, ch);
		}

	}
	 
	for ( i = 0;str[i] != '\0';i++) {
		printf("%c",str[i]);
	}
	return 0;
}

